package com.yun.zhong.fu.sharecenter.spring_origiond_code_study;

import com.yun.zhong.fu.sharecenter.entity.Share;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

/**
 * @Author RenPu
 * @Date 2022/10/23 15:37
 * @Version 1.0
 * @Description:  想要按照自己的意愿来控制bean的实例化，可以通过自定义BeanPostProcessor来实现。
 *                例如bean的初始化是通过NEW关键字，还是JDK动态代理或者CGLIB
 **/
@Configuration
public class StudentPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        if(bean instanceof Share){
            System.out.println("Share 对象=====实例化开始=====");
        }


        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof Share){
            System.out.println("Share 对象======实例化完毕====");
        }

        return bean;
    }
}
